Skip to content

Add client-side code folding fallback for virtual workspaces#5509

Draft
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-syntax-code-folding-issue
Draft

Add client-side code folding fallback for virtual workspaces#5509
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-syntax-code-folding-issue

Conversation

Copilot AI commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

In virtual workspaces (e.g. Azure DevOps / GitHub repos opened via Open Remote Repository), PowerShell Editor Services cannot run, so the LSP-powered syntax folding is unavailable and users lose code folding entirely once the workspace is trusted.

Changes

  • src/features/Folding.ts (new) — A FoldingRangeProvider that ports the server's TokenOperations.FoldableReferences algorithm to TypeScript: a tokenizer (braces, parens, here-strings, braced variables, block/line comments, #region/#endregion) plus the two-pass "largest range wins" folding logic. Registered only when isVirtualWorkspace() is true, so it never competes with LSP folding in local workspaces.
  • src/extension.ts — Registers FoldingFeature as a standalone (non-LSP) feature.
  • package.json — Declares the virtualWorkspaces capability as "limited", signaling partial support.
  • test/features/Folding.test.ts (new) — Ports the PSES folding test corpus plus provider-level tests.

Behavior notes

  • Honors powershell.codeFolding.enable: when disabled, returns [] so VS Code falls back to indentation-based folding.
  • Honors powershell.codeFolding.showLastLine (decrements each region's end line by one to match the server).
  • Output is line-based per the VS Code FoldingRange API; character offsets from PSES are retained internally for test parity.

This is intentionally partial support — features requiring PowerShell execution (debugging, terminals, analysis) remain unavailable in virtual workspaces, as they need real local file paths.

Copilot AI changed the title [WIP] Fix syntax-based code folding in virtual workspaces Add client-side code folding fallback for virtual workspaces Jun 10, 2026
Copilot AI requested a review from andyleejordan June 10, 2026 01:23
@JustinGrote

Copy link
Copy Markdown
Collaborator

@andyleejordan are we sure it can't run? Can't we treat the files like we do with untitled files and run analysis based on the contents? LSP 3.18 would be ideal for this but not strictly necessary, as long as we can get the content of the file from the virtual workspace and AST it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Syntax-based code folding unavailable in virtual workspaces

3 participants